#!/bin/zsh

p_w_d=$PWD
list=(sys example net tour sublime-build dl talks term blog arch image gddo mod dep snappy oauth2 tools geo groupcache build sync glog appengine lint website playground debug mock proposal leveldb text perf sublime-config freetype benchmarks xerrors gofrontend cwg scratch winstrap time protobuf review crypto mobile vgo exp)
len_of_list=${#list[*]}



change_aleardy(){
    echo $1 > ./aleardy.file
}
gclll(){
    finished_flag=0
    git clone https://github.com/golang/$1 $1 && export aleardy=`expr $(cat ./aleardy.file) + 1 ` && echo "第${aleardy}个包已克隆, 还剩`expr $len_of_list - $aleardy`个" && finished_flag=1

    if test $finished_flag -eq 1
    then
        change_aleardy $aleardy
    elif test $2 -eq 10
    then
        echo "放弃clone $1"
    else
        gclll $1 $[$2+1]
    fi
}



if test $# -eq 0
then
    for val in $list ; do
        gclll $val 0 &
    done
else
    for val in $list ; do
        cd $p_w_d/$val && git pull origin master &
    done
fi
